package com.megalith.controller;

import com.megalith.dto.CandidateUserDTO;
import com.megalith.service.ProcessEngineUserService;
import com.megalith.utils.RequestResponseUtil;
import com.megalith.vo.Result;
import com.megalith.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.flowable.idm.api.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 流程引擎用户管理
 * @Author lfp
 * @Date 2022/7/15
 * @Version 1.0
 */
@RestController
@Api(tags = "流程引擎用户管理")
@RequestMapping("user")
public class ProcessEngineUserController {
    @Autowired
    private ProcessEngineUserService processEngineUserService;

    @ApiOperation(value = "添加用户")
    @PostMapping("add")
    public Result<User> addUser(@Validated @RequestBody CandidateUserDTO userDTO, BindingResult result){
        if (result.hasErrors()) {
            return RequestResponseUtil.doBindingResultHandel(result);
        }else {
            return processEngineUserService.addUser(userDTO);
        }
    }

    @ApiOperation(value = "删除用户")
    @DeleteMapping("delete/{userId}")
    public Result deleteUser(@PathVariable String userId){
        return processEngineUserService.deleteUser(userId);
    }

    @ApiOperation(value = "用户列表查询")
    @GetMapping("list")
    public Result<List<UserVO>> listUser(CandidateUserDTO userDTO){
        return Result.ok(processEngineUserService.listUser(userDTO));
    }
}
